package com.choosefine.it.project.service;

import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.project.model.ProjectCooperateBus;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.project.dao.ProjectCooperateBusMapper;
import com.choosefine.it.project.model.dto.ProjectCooperateBusSaveDTO;
import com.choosefine.it.project.model.vo.ProjectCooperateBusVO;
import com.choosefine.it.project.model.vo.SupplierInfoVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Comments：说明
 * Author：
 * Create Date：2017/3/10
 * Modified By：
 * Modified Date：
 * Why & What is modified：
 * Version：v1.0
 */
@Service("projectCooperateBusService")
public class ProjectCooperateBusService {
    @Autowired
    ProjectCooperateBusMapper projectCooperateBusMapper;

    /**
     * @Author maojun
     * @Date 2017/2/15 17:27
     */
    public Page<ProjectCooperateBusVO> queryProjectCooperateBus(Map<String, Object> params, PageDTO pageDto){
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        Page<ProjectCooperateBusVO> list=projectCooperateBusMapper.queryProjectCooperateBus(params);
        return list;
    }
    /**
     * @Author maojun
     * @Date 2017/2/15 17:27
     */
    public Page<SupplierInfoVO> querySupplier(Map<String, Object>params, PageDTO pageDto){
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        Page<SupplierInfoVO> list=projectCooperateBusMapper.querySupplier(params);
        return list;
    }
    /**
     * @Author maojun
     * @Date 2017/2/16 9:50
     */
    public int changePartnership(Map<String,Object> params){
        return projectCooperateBusMapper.changePartnership(params);
    }

    /**
     * @Author maojun
     * @Date 2017/2/16 12:02
     */
    public int  saveProjectCooperateBus(List<ProjectCooperateBusSaveDTO> list){
        int count=0;
        if(list != null && list.size() > 0){
            for (ProjectCooperateBusSaveDTO projectCooperateBusSaveDTO : list){
                ProjectCooperateBus projectCooperateBus=new ProjectCooperateBus();
                projectCooperateBus.setCompanyName(projectCooperateBusSaveDTO.getCompanyName());
                projectCooperateBus.setCompanyType(projectCooperateBusSaveDTO.getCompanyType());
                projectCooperateBus.setCorporation(projectCooperateBusSaveDTO.getCorporation());
                projectCooperateBus.setProjectCode(projectCooperateBusSaveDTO.getProjectCode());
                projectCooperateBus.setTenantRole(projectCooperateBusSaveDTO.getTenantRole());
                projectCooperateBus.setUserCode(projectCooperateBusSaveDTO.getUserCode());
                projectCooperateBus.setCtime(DateUtils.getNowTime());
                projectCooperateBusMapper.saveProjectCooperateBus(projectCooperateBus);
                count++;
            }
        }

        return count;
    }
}
